home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / purge.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  610 b   |  29 lines

  1. //: :purge.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Delete pointers in an STL sequence container
  7. #ifndef PURGE_H
  8. #define PURGE_H
  9. #include <algorithm>
  10.  
  11. template<class Seq> void purge(Seq& c) {
  12.   typename Seq::iterator i;
  13.   for(i = c.begin(); i != c.end(); i++) {
  14.     delete *i;
  15.     *i = 0;
  16.   }
  17. }
  18.  
  19. // Iterator version:
  20. template<class InpIt>
  21. void purge(InpIt begin, InpIt end) {
  22.   while(begin != end) {
  23.     delete *begin;
  24.     *begin = 0;
  25.     begin++;
  26.   }
  27. }
  28. #endif // PURGE_H ///:~
  29.